/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dw2;

import java.awt.Image;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
/**
 *
 * @author Brian
 */
public class npcAnimals extends NPC {
    protected int life_value = -10;
    protected int cycle_count = 0;
    protected static Random randomGenerator = new Random();

    protected static ArrayList<Image> image = new ArrayList<Image>();

    public static void initImage(Image images[])
    {
        image.addAll(Arrays.asList(images));
        
    }
    
    public npcAnimals(int x, int y, int direction_to_face,int points){
        super(x - 100,y-image.get(0).getHeight(null) - 100,direction_to_face,0);
        WALK_SPEED = 2;
        ATTACK_POWER = 0;
        FIRING_RATE = 0;
        //super.x += randomGenerator.nextInt(50);
        super.y += randomGenerator.nextInt(50);
        graphics.add(new DWGraphics_Animation(image.get(0),5,4));
    }
    
    public void action(Main mainparent,Worm player)
    {
        this.player = player;
        move(mainparent,player.getHeadPosition());
        if(player.hitHead(graphics.get(graphics_index).getBounds())==true)
        {
            new AePlayWave("Sounds\\bit1.wav").start();
            player.add_points(points);
            deathParticles(mainparent,player);
            if(player.getHP() < 100){
                player.hurtWorm(life_value);
                if(player.getHP() > 100){
                    player.setHP(100);
                }
            }
            player.setHit();
            mainparent.removeNPC(this);
            return;
        }
    }
    public void move(Main mainparent,Point head_pos)
    {
        Run();
        if(direction == 1)
            x -= WALK_SPEED;
        else
            x += WALK_SPEED;

        if(x < -64 && direction == 1)
            x = mainparent.getMaxWidth();
        if(x > mainparent.getMaxWidth() && !(direction == 1))
            x = -64;
    }

    //RUNS AWAY//
    public int Run(){
        int Dis = Math.abs(x - player.getXpos());
        if(player.getAboveGround() && x > player.getXpos() && Dis < 200){
           if(direction == 1){
               direction = 0;
               return 1;
           }
        }
         if(player.getAboveGround() && x < player.getXpos() && Dis < 200){
           if(direction == 0){
               direction = 1;
               return 0;
           }
        }
        return -1;
    }
}
    
   
